home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / PowerPlant / LEnhancedIconPane / LEnhancedIconPane.cp < prev    next >
Encoding:
Text File  |  1996-09-14  |  6.5 KB  |  204 lines  |  [TEXT/CWIE]

  1. // ===========================================================================
  2. //    File:                    LEnhancedIconPane.cp
  3. //  Version:                1.0 - Feb 08, 1995
  4. //    Author:                    Mike Shields (mshields@inconnect.com)
  5. //                            
  6. //    Copyright ©1994-1996 Mike Shields. All rights reserved.
  7. //    I hereby grant users of LEnhancedIconPane permission to use it (or any modified 
  8. //    version of it) in applications (or any other type of Macintosh software 
  9. //    like extensions -- freeware, shareware, commercial, or other) for free, 
  10. //    subject to the terms that:
  11. //
  12. //        (1)  This agreement is non-exclusive.
  13. //
  14. //        (2)  I, Mike Shields, retain the copyright to the original source code.
  15. //
  16. //    These two items are the only required conditions for use. However, I do have 
  17. //    an additional request. Note, however, that this is only a request, and 
  18. //    that it is not a required condition for use of this code.
  19. //
  20. //        (1) That I be given credit for LEnhancedIconPane code in the copyrights or 
  21. //            acknowledgements section of your manual or other appropriate documentation.
  22. //
  23. //
  24. //    I would like to repeat that this last item is only a request. You are prefectly 
  25. //    free to choose not to do any or all of them.
  26. //    
  27. //        This source code is distributed in the hope that it will be useful,
  28. //        but WITHOUT ANY WARRANTY; without even the implied warranty of
  29. //        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  30. // ===========================================================================
  31. //    LEnhancedIconPane.h        <- double-click + Command-D to see class declaration
  32. //
  33. //
  34. // LEnhancedIconPane is an enhancement to the PP supplied LIconPane Class. This
  35. // subclass give the user the ability to specify all of the parameters in the call
  36. // to PlotIconID. Namely the alignment, label and selection property.
  37. //
  38. // Note: For more info on the PlotIconID calls see TN QD 18 - 
  39. // Drawing Icons the System 7 Way
  40. //
  41. #include "LEnhancedIconPane.h"
  42.  
  43. #include <LStream.h>
  44.  
  45. #ifndef __ICONS__
  46. #include <Icons.h>
  47. #endif
  48.  
  49. // ---------------------------------------------------------------------------
  50. //        • CreateFromStream
  51. // ---------------------------------------------------------------------------
  52. //    Create a new IconPane object from the data in a Stream
  53.  
  54. LEnhancedIconPane* LEnhancedIconPane::CreateFromStream(LStream *inStream)
  55. {
  56.     return (new LEnhancedIconPane(inStream));
  57. }
  58.  
  59. // ---------------------------------------------------------------------------
  60. //        • LEnhancedIconPane
  61. // ---------------------------------------------------------------------------
  62. //    Default Constructor
  63.  
  64. LEnhancedIconPane::LEnhancedIconPane()
  65.     : mAlignment(atNone), mState(ttNone), mLabel(ttNone)
  66. {
  67. }
  68.  
  69.  
  70. // ---------------------------------------------------------------------------
  71. //        • LEnhancedIconPane(const LEnhancedIconPane&)
  72. // ---------------------------------------------------------------------------
  73. //    Copy Constructor
  74.  
  75. LEnhancedIconPane::LEnhancedIconPane(const LEnhancedIconPane &inOriginal)
  76.         : LIconPane(inOriginal)
  77. {
  78.     SetAlignment(inOriginal.GetAlignment());
  79.     SetIconState(inOriginal.GetIconState());
  80.     SetIconLabel(inOriginal.GetIconLabel());
  81. }
  82.  
  83.  
  84. // ---------------------------------------------------------------------------
  85. //        • LEnhancedIconPane(SPaneInfo&, Str255, ResIDT)
  86. // ---------------------------------------------------------------------------
  87. //    Construct from parameters. Use this constructor to create a IconPane
  88. //    from runtime data.
  89.  
  90. LEnhancedIconPane::LEnhancedIconPane(const SPaneInfo &inPaneInfo,
  91.                     ResIDT inIconID, Int16 inAlignment,
  92.                     Int16 inState, Int16 inLabel)
  93.         : LIconPane(inPaneInfo, inIconID), mAlignment(inAlignment), mState(inState), 
  94.             mLabel(inLabel)
  95.  
  96. {
  97. }    
  98.  
  99.  
  100. // ---------------------------------------------------------------------------
  101. //        • LEnhancedIconPane(LStream*)
  102. // ---------------------------------------------------------------------------
  103. //    Construct from data in a Stream
  104.  
  105. LEnhancedIconPane::LEnhancedIconPane(LStream *inStream)
  106.         : LIconPane(inStream)
  107. {
  108.     inStream->ReadData(&mAlignment, sizeof(Int16));
  109.     inStream->ReadData(&mState, sizeof(Int16));
  110.     inStream->ReadData(&mLabel, sizeof(Int16));
  111. }
  112.  
  113.  
  114. // ---------------------------------------------------------------------------
  115. //        • ~LEnhancedIconPane
  116. // ---------------------------------------------------------------------------
  117. //    Destructor
  118.  
  119. LEnhancedIconPane::~LEnhancedIconPane()
  120. {
  121. }
  122.  
  123. // ---------------------------------------------------------------------------
  124. //        • GetAlignment
  125. // ---------------------------------------------------------------------------
  126. //    Get the alignment to draw the icon with
  127.  
  128. Int16 LEnhancedIconPane::GetAlignment() const
  129. {
  130.     return mAlignment;
  131. }
  132.  
  133.  
  134. // ---------------------------------------------------------------------------
  135. //        • SetAlignment
  136. // ---------------------------------------------------------------------------
  137. //    Set the alignment to draw the icon with
  138.  
  139. void LEnhancedIconPane::SetAlignment(Int16 inAlignment)
  140. {
  141.     mAlignment = inAlignment;
  142. }
  143.  
  144.  
  145. // ---------------------------------------------------------------------------
  146. //        • GetIconState
  147. // ---------------------------------------------------------------------------
  148. //    Get the icon state (ie. enable, disabled, selected, etc) to draw the icon as
  149.  
  150. Int16 LEnhancedIconPane::GetIconState() const
  151. {
  152.     return mState;
  153. }
  154.  
  155.  
  156. // ---------------------------------------------------------------------------
  157. //        • SetIconState
  158. // ---------------------------------------------------------------------------
  159. //    Set the icon state (ie. enable, disabled, selected, etc) to draw the icon as
  160.  
  161. void LEnhancedIconPane::SetIconState(Int16 inIconState)
  162. {
  163.     mState = inIconState;
  164. }
  165.  
  166.  
  167. // ---------------------------------------------------------------------------
  168. //        • GetIconLabel
  169. // ---------------------------------------------------------------------------
  170. //    Get the icon finder label (ie. none(0), 1, 2, 3, etc) to draw the icon as
  171.  
  172. Int16 LEnhancedIconPane::GetIconLabel() const
  173. {
  174.     return mLabel;
  175. }
  176.  
  177.  
  178. // ---------------------------------------------------------------------------
  179. //        • SetIconLabel
  180. // ---------------------------------------------------------------------------
  181. //    Set the icon finder label (ie. none(0), 1, 2, 3, etc) to draw the icon as
  182.  
  183. void LEnhancedIconPane::SetIconLabel(Int16 inIconLabel)
  184. {
  185.     mLabel = inIconLabel;
  186. }
  187.  
  188.  
  189. // ---------------------------------------------------------------------------
  190. //        • DrawSelf
  191. // ---------------------------------------------------------------------------
  192. //    Draw the IconPane
  193.  
  194. void LEnhancedIconPane::DrawSelf()
  195. {
  196.     Rect            frame;
  197.     
  198.     CalcLocalFrameRect(frame);
  199.     
  200.     ::PlotIconID(&frame, mAlignment, mState + (mLabel << 8), mIconID);
  201. }
  202.  
  203.  
  204.